﻿@* DXCOMMENT: Configure GridView *@

@Html.DevExpress().GridView(
    settings =>
    {
        settings.Name = "District Grid";
        settings.CallbackRouteValues = new { Controller = "District", Action = "Edit", districtId = ViewBag.districtId };
        settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "District", Action = "Save", districtId = ViewBag.districtId };

        settings.CommandColumn.CustomButtons.Add(new GridViewCommandColumnCustomButton() { ID = "approve", Text = "Approve" });
        settings.ClientSideEvents.CustomButtonClick = string.Format("function(s, e) {{ if(e.buttonID == 'approve') window.location.href = '{0}' }}",
            DevExpressHelper.GetUrl(new { Controller = "District", Action = "Approve", districtId = ViewBag.districtId }));

        
        settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
        settings.SettingsPager.Visible = false;
        settings.SettingsPager.PageSize = 20;
        settings.Settings.ShowVerticalScrollBar = true;
        settings.Settings.VerticalScrollableHeight = 350;
        settings.Settings.VerticalScrollBarStyle = GridViewVerticalScrollBarStyle.Virtual;
        settings.ControlStyle.Paddings.Padding = System.Web.UI.WebControls.Unit.Pixel(0);
        settings.ControlStyle.Border.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(0);
        settings.ControlStyle.BorderBottom.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(1);

        settings.CommandColumn.EditButton.Visible = true;
        settings.CommandColumn.Visible = true;
        settings.SettingsEditing.Mode = GridViewEditingMode.EditForm;

        settings.KeyFieldName = "StoreNum";

        // DXCOMMENT: Configure grid's columns in accordance with data model fields
        settings.Columns.Add(col =>
        {
            col.FieldName = "StoreNum";
            col.Caption = "Store Number";
            col.EditFormSettings.Visible = DefaultBoolean.False;
            col.ReadOnly = true;
            col.Width = System.Web.UI.WebControls.Unit.Percentage(10);
        });

        settings.Columns.Add(col =>
        {
            col.FieldName = "DistrictID";
            col.Caption = "District ID";
            col.EditFormSettings.Visible = DefaultBoolean.False;
            col.ReadOnly = true;
            col.Width = System.Web.UI.WebControls.Unit.Percentage(10);
            col.Visible = false;
        });

        settings.Columns.Add(col =>
        {
            col.FieldName = "Name";
            col.Caption = "Name";
            col.EditFormSettings.Visible = DefaultBoolean.False;
            col.ReadOnly = true;
            col.Width = System.Web.UI.WebControls.Unit.Percentage(10);
        });
        
        settings.Columns.Add("DaysWorked", "Days Worked", MVCxGridViewColumnType.TextBox);
        settings.Columns.Add("DaysSick", "Days Sick", MVCxGridViewColumnType.TextBox);
        settings.Columns.Add("DaysVacation", "Days Vacation", MVCxGridViewColumnType.TextBox);
        settings.Columns.Add("DaysOff", "Days Off", MVCxGridViewColumnType.TextBox);
        settings.Columns.Add("TotalDays", "Total Days", MVCxGridViewColumnType.TextBox);
        settings.Columns.Add(col =>
        {
            col.FieldName = "WeeklyLabor";
            col.Caption = "Weekly Labor";
            col.EditFormSettings.Visible = DefaultBoolean.False;
            col.ReadOnly = true;
            col.Width = System.Web.UI.WebControls.Unit.Percentage(10);
        });

        settings.Columns.Add("Approved", "Approved", MVCxGridViewColumnType.CheckBox);
        settings.SettingsEditing.Mode = GridViewEditingMode.Inline;
    }).Bind(Model).GetHtml();   